const webSocketServer = require('ws').Server;
const wss = new webSocketServer({ port: 8000 });
wss.on('connection', function (ws) {
  ws.on('message', function (message) {
    // 监听接收的数据
    console.log(message);
  });

  let data = {
    name: '张三',
    age: 24
  }
  setInterval(function () {
    ws.send(JSON.stringify(data));
  }, 1000);
})